package spring.batch.shareDataContext;

import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.RepeatStatus;

/**
 * @Author: huhx
 * @Date: 2017-11-02 下午 8:41
 */
public class SetDataContextTasklet implements Tasklet {

    @Override
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
        ExecutionContext jobExecutionContext = chunkContext.getStepContext().
                        getStepExecution().
                        getJobExecution().
                        getExecutionContext();
        jobExecutionContext.putString("username", "huhx");
        System.out.println("set data tasklet.");
        return RepeatStatus.FINISHED;
    }
}
